<?php
declare (strict_types = 1);

namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;//单例设计模式

class Users
{
    public function index()
    {
        // 请求接参
        $uname      = Request::get('uname','','trim,htmlspecialchars,strip_tags');
        $permission = Request::get('permission','2','trim,htmlspecialchars,strip_tags');

        // 组装查询语句
        $db = Db::table('ecm_users')->field(true);

        if('' !== $uname){//0 '0'  [] ''  false  null
            $db->where('uname','like','%'.$uname.'%');
        }
        View::assign('uname',$uname);

        if('2' != $permission){
            $db->where('permission',$permission);
        }
        View::assign('permission',$permission);


        // 执行查询获取结果
        $list = $db->select();

        // 赋值
        $empty = "<tr><td colspan=''>暂无数据</td></tr>";
        View::assign('empty',$empty);

        // 渲染
        return View::fetch('',['list'=>$list]);
    }
}
